﻿package frEngine.animateControler.uvControler
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import flash.events.*;
    import frEngine.*;
    import frEngine.animateControler.*;
    import frEngine.animateControler.keyframe.*;
    import frEngine.event.*;
    import frEngine.math.*;
    import frEngine.shader.*;

    public class UVRotateController extends MeshAnimateBase
    {
        public var UVrotate:Vector.<Number>;

        public function UVRotateController()
        {
            return;
        }// end function

        override public function get type() : int
        {
            return AnimateControlerType.UVRotateAnimationController;
        }// end function

        override protected function setSurfaceHander(event:Event) : void
        {
            super.setSurfaceHander(event);
            this.reBuilderHander(null);
            FrEventDispatcher.instance.proxyAddEventListener(targetMesh.material, Engine3dEventName.MATERIAL_REBUILDER, this.reBuilderHander);
            return;
        }// end function

        private function reBuilderHander(event:Event) : void
        {
            this.UVrotate = targetMesh.material.materialParams.UVrotateValue;
            return;
        }// end function

        override protected function getBaseValue(param1:Pivot3D) : Object
        {
            return targetMesh.material.materialParams.uvRotateBaseAngle;
        }// end function

        override protected function setTargetProperty(param1) : void
        {
            var _loc_2:* = param1;
            this.UVrotate[2] = param1;
            return;
        }// end function

        override public function parserKeyFrames(param1:Object) : void
        {
            var _loc_4:NodeAnimateKey = null;
            var _loc_6:Object = null;
            var _loc_7:Boolean = false;
            var _loc_8:BezierVo = null;
            var _loc_9:Object = null;
            var _loc_10:Number = NaN;
            var _loc_2:* = param1.length;
            var _loc_3:* = MathConsts.DEGREES_TO_RADIANS;
            var _loc_5:int = 0;
            while (_loc_5 < _loc_2)
            {
                
                _loc_6 = param1[_loc_5];
                _loc_7 = _loc_6.isLineTween == null ? (true) : (_loc_6.isLineTween);
                _loc_8 = new BezierVo(_loc_6.LX, _loc_6.LY, _loc_6.RX, _loc_6.RY, _loc_7);
                _loc_9 = _loc_6.attributes;
                if (_loc_9 is Array)
                {
                    _loc_10 = _loc_9[0].value;
                }
                else
                {
                    _loc_10 = Number(_loc_9);
                }
                var _loc_11:int = 0;
                _loc_10 = 0;
                _loc_4 = new NodeAnimateKey(_loc_6.index, _loc_10 * _loc_3, _loc_8);
                _keyframes.push(_loc_4);
                _loc_5++;
            }
            _keyframes.sortOn("frame", Array.NUMERIC);
            this.setPlayLable(this.defaultLable);
            this.defaultLable.change(0, _keyframes[(_loc_2 - 1)].frame);
            _cache.length = 0;
            return;
        }// end function

        override public function editKeyFrame(param1:Object, param2:int, param3:String, param4, param5:BezierVo) : Object
        {
            return super.editKeyFrame(param1, param2, param3, param4 * MathConsts.DEGREES_TO_RADIANS, param5);
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            FrEventDispatcher.instance.proxyRemoveEventListener(targetMesh.material, Engine3dEventName.MATERIAL_REBUILDER, this.reBuilderHander);
            var _loc_2:* = targetMesh.material.materialParams;
            _loc_2.setUvRotateBase(_loc_2.uvRotateBaseAngle);
            super.dispose();
            return;
        }// end function

    }
}
